package com.tianji.aigc.controller;


import com.tianji.aigc.service.IChatSessionService;
import com.tianji.aigc.vo.ChatHistoryVO;
import com.tianji.aigc.vo.MessageVO;
import com.tianji.aigc.vo.SessionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 对话session 前端控制器
 * </p>
 *
 * @author mr.wu
 * @since 2025-09-02
 */
@RestController
@RequestMapping("/session")
public class ChatSessionController {

    @Autowired
    private IChatSessionService chatSessionService;


    /**
     * 新建会话
     * @param num
     * @return
     */
    @PostMapping
    public SessionVO newSession(@RequestParam(value = "n", defaultValue = "3") Integer num) {
        return chatSessionService.newSession(num);
    }

    /**
     * 热门问题
     * @param num
     * @return
     */
    @GetMapping("/hot")
    public List<SessionVO.Example> hotExampleList(@RequestParam(value = "n", defaultValue = "3") Integer num){
        return chatSessionService.hotExampleList(num);
    }


    /**
     * 查询会话详情（查询redis里每个会话对应的多轮对话消息列表）
     * @param sessionId
     * @return
     */
    @GetMapping("/{sessionId}")
    public List<MessageVO> getMessageList(@PathVariable("sessionId") String sessionId) {
        return chatSessionService.getMessageList(sessionId);
    }

    /**
     * 查询会话历史
     * @return
     */
    @GetMapping("/history")
    public Map<String,List<ChatHistoryVO>> getChatSessionHistory() {
        return chatSessionService.getChatSessionHistory();
    }
}
